package com.teach.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.teach.dto.AuthUser;
import com.teach.dto.ReturnData;
import com.teach.service.UserService;

import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
public class PayController {
	
	@Value("${server.port}")
	private Integer port;
	
	@Autowired
	private UserService service;

	@GetMapping("/hello")
	public String doHello(String name) {
		log.debug(port+" hello " + name);
		return port+" hello " + name;
	}
	
	@PostMapping("/pay")
	public ReturnData<AuthUser> doPay(Double money,AuthUser user){
		log.debug(port+" 支付金额："+money);
		return new ReturnData<AuthUser>(1, port+" 支付成功:"+money, user);
	}
	
	@GetMapping("/remote-login")
	public Object doLogin(String userName,String userPwd) {
		log.debug(port+" 使用远程登录,{} - {}",userName,userPwd);
		return service.login(userName, userPwd);
	}
	
	@GetMapping("/remote-list")
	public Object doList() {
		return service.list();
	}
	
	@GetMapping("/remote-get/{id}")
	public ReturnData<AuthUser> get(@PathVariable("id")Long id){
		return service.get(id);
	}
}
